#region Using Statements
using System;
using System.IO;
using System.Xml;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Runtime.Remoting;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
#endregion

namespace SkyBurner
{
    // PostScreenEffectsManager class
    //
    #region PostScreenEffectsManager class
    public class PostScreenEffectsManager : BaseObject
    {
        protected Rectangle m_screenRect;
        protected Collection<PostScreenEffectBase> m_effectsList;

        public PostScreenEffectsManager(BaseGame pGame)
            : base(pGame)
        {
            m_effectsList = new Collection<PostScreenEffectBase>();
            m_screenRect = new Rectangle(0, 0, m_Game.GraphicsDevice.Viewport.Width, m_Game.GraphicsDevice.Viewport.Height);
        }

        public void Draw(GameTime gameTime, Texture2D pScreenTexture)
        {
            if (m_effectsList.Count > 0)
            {
                int i = 0;
                while (i < m_effectsList.Count)
                {
                    PostScreenEffectBase postScreenEffect = m_effectsList[i];

                    postScreenEffect.Begin(gameTime, m_Game.SpriteBatch);
                    postScreenEffect.Draw(gameTime, m_Game.SpriteBatch, m_screenRect, pScreenTexture);
                    postScreenEffect.End(m_Game.SpriteBatch);

                    if (!postScreenEffect.Active)
                    {
                        m_effectsList.Remove(postScreenEffect);
                        continue;
                    }
                    i++;
                }
            }
            else
            {
                m_Game.SpriteBatch.Begin(SpriteBlendMode.None, SpriteSortMode.Immediate, SaveStateMode.SaveState);
                m_Game.SpriteBatch.Draw(pScreenTexture, m_screenRect, Color.White);
                m_Game.SpriteBatch.End();
            }
        }

        public void AddPostScreenEffect(PostScreenEffectBase pPostScreenEffect)
        {
            m_effectsList.Add(pPostScreenEffect);
        }

        public void RemovePostScreenEffect(PostScreenEffectBase pPostScreenEffect)
        {
            m_effectsList.Remove(pPostScreenEffect);
        }
    }
    #endregion
}
